package com.kk.interceptor;

import lombok.extern.log4j.Log4j2;
import org.apache.el.parser.Token;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @author: kevin
 * @data: 2018-08-20 11:38
 * @desc:
 */
@Log4j2
//@Configuration
class WebMvcConfiguration extends WebMvcConfigurationSupport {

    @Bean   //为了注入Redis
    public TokenInterceptor tokenInterceptor() {
        return new TokenInterceptor();
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new CrossInterceptor()).addPathPatterns("/**");
//        log.info("跨域拦截器注册成功！");
//        registry.addInterceptor(tokenInterceptor()).addPathPatterns("/user*/**","/api/**","/get_info");
        registry.addInterceptor(new OptionsInterceptor()).addPathPatterns("/**");
//
//        log.info("Options请求拦截器注册成功！");

        // 不在这里实现跨域，这里实现跨域会导致拦截器return false的情况下跨域失败，改为拦截器实现
    /*@Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET","POST","PUT","DELETE","OPTIONS")
                .allowedHeaders("X-Access-Token");
        log.debug("允许跨域配置成功！");
    }
   */

    }
}
